<?php
namespace Common\Models;
use Common\BaseModel;
use Phalcon\Paginator\Adapter\Model as PaginatorModel;
class Questions extends BaseModel
{
	public $res;
	public $expire;
    public function initialize()
    {
        parent::initialize();
        $this->hasMany('file_id','File','id');
    }

    public function getSource()
    {
	    return "f_questions";
    }


    /**
     * @问题列表
     * @return mixed
     */
    public function questionlist(){

        $conditions = "isshow=1";
        $order="created_at desc";
        $list = $this::find(
            array(
                $conditions,
                "order" => $order,
            )
        );
        return $list;
    }


    /**
     * @return mixed
     */
    public function find_by_questionlist_cate($qcat_id,$limit=5){
        $conditions = "isshow=1 AND qcat_id={$qcat_id}";
        $order="created_at desc";
        $limit = $limit ? $limit : 5;
        if($limit){
            $list = $this->find(
                array(
                    $conditions,
                    "order" => $order,
                    "limit" => $limit,
                )
            );
        }else{
            $list = $this->find(
                array(
                    $conditions,
                    "order" => $order,
                )
            );
        }
        if($list){
            return $list->toarray();
        }else{
            return $list;
        }
    }




    public function get_by_id($id){
        $info = $this->findFirstById($id);
        if($info){
            return $info->toarray();
        }else{
            return false;
        }
    }


}
